import axios from "axios";
import {
    MessageBox,
    Message
} from "element-ui";
// import store from '@/store'
// import { getToken } from '@/utils/auth'

// 创建一个axios的实例
const service = axios.create({
    //基础路径-根路径    url = base url + request url  真实路径就是baseURL加上你拼接的url路径http://localhost:8081/menu/tree
    baseURL: "http://localhost:8081",
    //超时时间 5s
    timeout: 5000, // request timeout
});

// request interceptor
// service.interceptors.request.use(
//   config => {
//     // do something before request is sent

//     if (store.getters.token) {
//       // let each request carry token
//       // ['X-Token'] is a custom headers key
//       // please modify it according to the actual situation
//       config.headers['X-Token'] = getToken()
//     }
//     return config
//   },
//   error => {
//     // do something with request error
//     console.log(error) // for debug
//     return Promise.reject(error)
//   }
// )

// response interceptor(请求的拦截器)
service.interceptors.response.use(
    //response请求的响应数据
    (response) => {
        const res = response.data;
        return res;

    },
    (error) => {
        //打印错误消息
        console.log("err" + error); // for debug
        Message({
            message: error.message,
            type: "error",
            duration: 5 * 1000,
        });
        return Promise.reject(error);
    }
);

export default service;